/*
 * ColorUtils.java
 *
 *  created: 19.11.2011
 *  charset: UTF-8
 *  license: MIT (X11) (See LICENSE file for full license)
 */
package cz.mp.util;

import java.awt.Color;

/**
 *
 * @author Martin Pokorný
 * @version 0.1
 */
public class ColorUtils {

    /** */
    private ColorUtils() {
    }

    /**
     * 
     * @param color
     * @return  číslo barvy ve formátu 
     *      {@literal <RR_h><GG_h><BB_h>} (např {@literal 33FFCC})
     * @throws IllegalArgumentException
     */
    public static String getHTMLColor(Color color) {
        if (color == null) {
            throw new IllegalArgumentException("color = null");
        }
        String rr = StringUtils.leftTextPad(
                Integer.toString(color.getRed(), 16), 2, '0');
        String gg = StringUtils.leftTextPad(
                Integer.toString(color.getGreen(), 16), 2, '0');
        String bb = StringUtils.leftTextPad(
                Integer.toString(color.getBlue(), 16), 2, '0');
        return (rr + gg + bb).toUpperCase();
    }

}   // ColorUtils
